#include "musicitemwidget.h"
#include<QLabel>
#include<QToolButton>
#include<QVBoxLayout>
#include<QHBoxLayout>


MusicItemWidget::MusicItemWidget(int index, const QString &name, QWidget *parent)
    : QWidget{parent},
    index(index)
{
    this->cover_label=new QLabel(this);
    this->name_labe=new QLabel(name,this);
    this->index_label=new QLabel(QString::number(index),this);
    this->play_toolButton=new QToolButton(this);
    this->play_next_toolButton=new QToolButton(this);
    this->download_toolButton=new QToolButton(this);
    this->collect_toolButton=new QToolButton(this);
    this->more_toolButton=new QToolButton(this);

    this->cover_label->setObjectName("cover_label");
    this->name_labe->setObjectName("name_labe");
    this->index_label->setObjectName("index_label");
    this->play_toolButton->setObjectName("play_toolButton");
    this->play_next_toolButton->setObjectName("play_next_toolButton");
    this->download_toolButton->setObjectName("download_toolButton");
    this->collect_toolButton->setObjectName("collect_toolButton");
    this->more_toolButton->setObjectName("more_toolButton");

    this->play_toolButton->setIcon(QIcon("://image/tabIcon/play3-gray.svg"));
    this->play_next_toolButton->setIcon(QIcon("://image/tabIcon/add-music-list-gray.svg"));
    this->download_toolButton->setIcon(QIcon("://image/playbar/download.svg"));
    this->collect_toolButton->setIcon(QIcon("://image/playbar/collect.svg"));
    this->more_toolButton->setIcon(QIcon("://image/playbar/more.svg"));

    layoutUI();

    connect(this->play_toolButton,&QToolButton::clicked,[this](){emit playRequest(this->index);});
}

void MusicItemWidget::layoutUI()
{
    QHBoxLayout* hLayout=new QHBoxLayout(this);
    hLayout->addWidget(this->index_label);
    hLayout->addWidget(this->cover_label);
    hLayout->addWidget(this->name_labe);
    hLayout->addSpacerItem(new QSpacerItem(40,20,QSizePolicy::Expanding));
    hLayout->addWidget(this->play_toolButton);
    hLayout->addWidget(this->play_next_toolButton);
    hLayout->addWidget(this->download_toolButton);
    hLayout->addWidget(this->collect_toolButton);
    hLayout->addWidget(this->more_toolButton);

}

